package com.platform.server.service.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.platform.server.dao.EnterpriseDao;
import com.platform.server.dao.MessageDao;
import com.platform.server.dao.ServerDao;
import com.platform.server.dao.UserDao;
import com.platform.server.entity.EnterpriseInfo;
import com.platform.server.entity.Order;
import com.platform.server.entity.OrderSend;
import com.platform.server.entity.ServerOrder;
import com.platform.server.entity.User;
import com.platform.server.response.pojo.ReturnData;
import com.platform.server.service.EnterpriseService;
import com.platform.server.util.StringTools;

@Transactional
@Service
public class EnterpriseServiceImpl implements EnterpriseService {

	@Autowired
	private EnterpriseDao enterpriseDao;
	@Autowired
	private ServerDao  serverDao;
    @Autowired
    private MessageDao messageDao;
    @Autowired
    private UserDao userDao;
	 /**
    * 员工申请加入企业
    */
	@Override
	public ReturnData addEnterpriseInfo(EnterpriseInfo enterpriseInfo) {
		 if (StringTools.isEmpty(enterpriseInfo.getUser_id())  || StringTools.isEmpty(enterpriseInfo.getEnterprise_id()) ) {
	            return new ReturnData(12, "参数有误");
	        }		
	      //查询是否加入企业
		 Map<String,Object> selectEnterpriseInfo = enterpriseDao.selectEnterpriseUserInfo(enterpriseInfo);
		if(selectEnterpriseInfo==null){
			 return new ReturnData(12, "该企业不存在或未经平台审核通过");
		}
		 if(selectEnterpriseInfo.get("user_id")!=null){
			 return new ReturnData(12, "你已经申请加入该企业或企业已经邀请你，请等待");
		 }
		if(selectEnterpriseInfo.get("enterprise_id")!=null&&selectEnterpriseInfo.get("enterprise_id").toString().equals(enterpriseInfo.getUser_id())){
			 return new ReturnData(12, "企业用户不能成为企业员工");
		}
		String selectStaff = userDao.selectStaff(enterpriseInfo.getUser_id());
		if(!StringTools.isEmpty(selectStaff)&&selectStaff.equals("1")){
			 return new ReturnData(12, "您已经加入过企业");	
		}
		 enterpriseInfo.setEnterprise_id(selectEnterpriseInfo.get("id").toString());
		 int flag = enterpriseDao.addEnterpriseInfo(enterpriseInfo);
		 Map<String, Object> selectUserMobile = userDao.selectUserMobile(enterpriseInfo.getUser_id());
		 //添加企业的消息
		    Map<String, Object> hm = new HashMap<>();
	         hm.put("title", selectUserMobile.get("username").toString()+"申请加入您的企业");
	         hm.put("type", "1");
	         hm.put("recevicer_id", selectEnterpriseInfo.get("enterprise_id").toString());
	         hm.put("content", selectUserMobile.get("username").toString()+"申请加入您的企业");
	         messageDao.insertMessage(hm);
		 
		  if (flag == 1) {
	            return new ReturnData(200, "申请成功");
	        }
	        return new ReturnData(100,"申请失败");

	}
	 
	 /**
    * 查询企业报名的需求
    */

	@Override
	public ReturnData selectEnterpriseInfoSignUp(EnterpriseInfo enterpriseInfo) {
		 if (StringTools.isEmpty(enterpriseInfo.getUser_id())) {
	            return new ReturnData(12, "参数有误");
	        }		
		 List<Map<String,Object>> selectEnterpriseInfoSignUp = enterpriseDao.selectEnterpriseInfoSignUp(enterpriseInfo);
		 if(selectEnterpriseInfoSignUp!=null&&selectEnterpriseInfoSignUp.size()>0){
			 return new ReturnData(selectEnterpriseInfoSignUp,200, ""); 
		 }
		  return new ReturnData(100, "暂无数据");
	}
	 /**
     * 查询企业的员工
     */
	@Override
	public ReturnData selectEnterpriseStaffList(ServerOrder serverOrder) {
		 if (StringTools.isEmpty(serverOrder.getUser_id())) {
	            return new ReturnData(12, "参数有误");
	        }	
		 if(!StringTools.isEmpty(serverOrder.getSex())){
			 if(serverOrder.getSex().equals("0")){
				 serverOrder.setSex("");
			 }
		 }
		 List<Map<String,Object>> selectEnterpriseInfoSignUp = enterpriseDao.selectEnterpriseStaffList(serverOrder);
		 if(selectEnterpriseInfoSignUp!=null&&selectEnterpriseInfoSignUp.size()>0){
			 return new ReturnData(selectEnterpriseInfoSignUp,200, ""); 
		 }
		  return new ReturnData(100, "暂无数据");
	}
	
	 /**
	    * 企业派单给员工 
	    */
	@Override
	public ReturnData addEnterpriseOrderSend(OrderSend orderSend) {
		 if (StringTools.isEmpty(orderSend.getUser_id()) || StringTools.isEmpty(orderSend.getOrder_id()) || StringTools.isEmpty(orderSend.getEnterprise_id())) {
	            return new ReturnData(12, "参数有误");
	        }	
		 Map<String, Object> selectOrderSend = enterpriseDao.selectOrderSend(orderSend);
		 if(selectOrderSend!=null){
			 return new ReturnData(12, "该员工已派单");
		 }
		 OrderSend orderSend5 = new OrderSend();
		 orderSend5.setUser_id(orderSend.getUser_id());
		 List<Map<String,Object>> selectOrderSendList = enterpriseDao.selectOrderSendList(orderSend5);
		 Order selectOrderInfoByOrderId = serverDao.selectOrderInfoByOrderId(orderSend.getOrder_id());
		 for (Map<String, Object> map2 : selectOrderSendList) {
				if(map2.get("server_time")!=null&&map2.get("status")!=null&&map2.get("status").equals("服务中")){
    	        	try {
    					DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");

    					Date date =  df.parse( map2.get("server_time").toString());
    					Date date2 = df.parse( map2.get("end_time").toString());
    					Date time =  df.parse(selectOrderInfoByOrderId.getServer_time());
    					if(time.getTime()>=date.getTime()&&time.getTime()<=date2.getTime()){
    	 				   return new ReturnData(12, "当前服务时长以存在待服务订单!");	
    					}
    					Date time2 = df.parse(selectOrderInfoByOrderId.getEnd_time());
    					if(time2.getTime()>=date.getTime()&&time2.getTime()<=date2.getTime()){
    	 				   return new ReturnData(12, "当前服务时长以存在待服务订单!");	
    					}
    					if(time2.getTime()>=date.getTime() &&time.getTime()<=date.getTime()){
    						   return new ReturnData(12, "当前服务时长以存在待服务订单!");	
    					}
    				} catch (Exception e) {
    					// TODO Auto-generated catch block
    					  return new ReturnData(12, "当前服务时长以存在待服务订单!");	
    				}
      }
		}
		 
		 
		 OrderSend  orderSend2 = new OrderSend();
		 orderSend2.setOrder_id(orderSend.getOrder_id());
		 Map<String, Object> selectOrderSend2 = enterpriseDao.selectOrderSend(orderSend2);
		 int flag=0;
		 if(selectOrderSend2!=null){
			 orderSend.setIs_order("1");
			 flag = enterpriseDao.updateOrderSend(orderSend);
		 }else{
			 orderSend.setIs_order("1");
			  flag = enterpriseDao.addEnterpriseOrderSend(orderSend);
		 }

		  if (flag == 1) {
	            return new ReturnData(200, "派单成功");
	        }
	        return new ReturnData(100,"派单失败");
	}
	   /**
	    * 改派/强制接受/申请改派
	    */
	@Override
	public ReturnData updateOrderSend(OrderSend orderSend) {
		 if (StringTools.isEmpty(orderSend.getUser_id()) || StringTools.isEmpty(orderSend.getOrder_id()) || StringTools.isEmpty(orderSend.getEnterprise_id())) {
	            return new ReturnData(12, "参数有误");
	        }
		 Map<String, Object> selectOrderSend = enterpriseDao.selectOrderSend(orderSend);
		 if(selectOrderSend!=null){
			 if(selectOrderSend.get("is_order").equals("1")){
				 return new ReturnData(12, "该员工已派单");
			 }else if(selectOrderSend.get("is_order").equals("0")){
				 return new ReturnData(12, "您已经申请改派");
			 }
		 }
		 OrderSend orderSend5 = new OrderSend();
		 orderSend5.setUser_id(orderSend.getUser_id());
		 List<Map<String,Object>> selectOrderSendList = enterpriseDao.selectOrderSendList(orderSend5);
		 Order selectOrderInfoByOrderId = serverDao.selectOrderInfoByOrderId(orderSend.getOrder_id());
		 for (Map<String, Object> map2 : selectOrderSendList) {
				if(map2.get("server_time")!=null&&map2.get("status")!=null&&map2.get("status").equals("服务中")){
    	        	try {
    					DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");

    					Date date =  df.parse( map2.get("server_time").toString());
    					Date date2 = df.parse( map2.get("end_time").toString());
    					Date time =  df.parse(selectOrderInfoByOrderId.getServer_time());
    					if(time.getTime()>=date.getTime()&&time.getTime()<=date2.getTime()){
    	 				   return new ReturnData(12, "当前服务时长以存在待服务订单!");	
    					}
    					Date time2 = df.parse(selectOrderInfoByOrderId.getEnd_time());
    					if(time2.getTime()>=date.getTime()&&time2.getTime()<=date2.getTime()){
    	 				   return new ReturnData(12, "当前服务时长以存在待服务订单!");	
    					}
    					if(time2.getTime()>=date.getTime() &&time.getTime()<=date.getTime()){
    						   return new ReturnData(12, "当前服务时长以存在待服务订单!");	
    					}
    				} catch (Exception e) {
    					// TODO Auto-generated catch block
    					  return new ReturnData(12, "当前服务时长以存在待服务订单!");	
    				}
      }
		}
		 
		 
		 int flag = enterpriseDao.updateOrderSend(orderSend);
		  if (flag == 1) {
			  if(orderSend.getIs_order().equals("0")){
				  Map<String, Object> selectEnterId = enterpriseDao.selectEnterId(orderSend.getEnterprise_id());
				  Map<String, Object> selectUserMobile = userDao.selectUserMobile(orderSend.getUser_id());
				  //添加企业的消息
				    Map<String, Object> hm = new HashMap<>();
			         hm.put("title", "您的员工"+selectUserMobile.get("username").toString()+"申请改派订单");
			         hm.put("type", "1");
			         hm.put("recevicer_id", selectEnterId.get("user_id").toString());
			         hm.put("content", "您的员工"+selectUserMobile.get("username").toString()+"申请改派订单");
			         hm.put("enterprise_id", orderSend.getUser_id()+","+orderSend.getOrder_id()+","+orderSend.getEnterprise_id());
			         messageDao.insertMessage(hm);
				 }
			  if(orderSend.getIs_order().equals("3")){
//				  int deleteMessage = messageDao.deleteMessage(orderSend.getMsgId());
//				  if(deleteMessage==1){
					  Map<String, Object> selectEnterId = enterpriseDao.selectEnterId(orderSend.getEnterprise_id());
					  Map<String, Object> selectUserMobile = userDao.selectUserMobile(orderSend.getUser_id());
					  //添加企业的消息
					    Map<String, Object> hm = new HashMap<>();
				         hm.put("title", "您已同意"+selectUserMobile.get("username").toString()+"的申请改派，请重新改派");
				         hm.put("type", "1");
				         hm.put("recevicer_id", selectEnterId.get("user_id").toString());
				         hm.put("content", "您已同意"+selectUserMobile.get("username").toString()+"的申请改派，请重新改派");
				         messageDao.insertMessage(hm); 
//				  }
			
				 }
			  if(orderSend.getIs_order().equals("2")){
//				  int deleteMessage = messageDao.deleteMessage(orderSend.getMsgId());
//				  if(deleteMessage==1){
					  Map<String, Object> selectEnterId = enterpriseDao.selectEnterId(orderSend.getEnterprise_id());
					  Map<String, Object> selectUserMobile = userDao.selectUserMobile(orderSend.getUser_id());
					  //添加企业的消息
					    Map<String, Object> hm = new HashMap<>();
				         hm.put("title", "您已拒绝"+selectUserMobile.get("username").toString()+"的申请改派");
				         hm.put("type", "1");
				         hm.put("recevicer_id", selectEnterId.get("user_id").toString());
				         hm.put("content", "您已拒绝"+selectUserMobile.get("username").toString()+"的申请改派");
				         messageDao.insertMessage(hm); 
				         Map<String, Object> hd = new HashMap<>();
				         hd.put("title", "您的申请改派被企业驳回");
				         hd.put("type", "1");
				         hd.put("recevicer_id", selectUserMobile.get("id").toString());
				         hd.put("content", "您的申请改派被企业驳回");
				         messageDao.insertMessage(hd); 
//				         
//				  }
			  }
	            return new ReturnData(200, "操作成功");
	        }
	        return new ReturnData(100,"操作失败");
	}
	 /**
	   * 查询员工订单列表
	   */
	@Override
	public ReturnData selectOrderSendList(OrderSend orderSend) {
		 if (StringTools.isEmpty(orderSend.getUser_id())) {
	            return new ReturnData(12, "参数有误");
	        }
		 List<Map<String,Object>> selectOrderSendList = enterpriseDao.selectOrderSendList(orderSend);
		 if(selectOrderSendList!=null&&selectOrderSendList.size()>0){
			 return new ReturnData(selectOrderSendList,200, ""); 
		 }
		  return new ReturnData(100, "暂无数据");
	}
	 /**
	    * 查询企业服务列表
	    */
	@Override
	public ReturnData selectEnterpriseServerList(OrderSend orderSend) {
		 if (StringTools.isEmpty(orderSend.getUser_id())) {
	            return new ReturnData(12, "参数有误");
	        }
		 List<Map<String,Object>> selectOrderSendList = enterpriseDao.selectEnterpriseServerList(orderSend);
		 if(selectOrderSendList!=null&&selectOrderSendList.size()>0){
			 return new ReturnData(selectOrderSendList,200, ""); 
		 }
		  return new ReturnData(100, "暂无数据");
	}
	 /**
	    * 根据手机号新增员工
	    */
	@Override
	public ReturnData addEnterpriseUser(String mobile, String enterprise_user) {
		 if (StringTools.isEmpty(mobile) ||StringTools.isEmpty(enterprise_user)) {
	            return new ReturnData(12, "参数有误");
	        }
		 String selectUserInfoId = userDao.selectUserInfoId(mobile);
		 if(StringTools.isEmpty(selectUserInfoId)){
			 return new ReturnData(12, "没有这个用户");
		 }
		 ServerOrder serverOrder = new ServerOrder();
		 serverOrder.setUser_id(enterprise_user);
		 List<Map<String,Object>> selectEnterpriseStaffList = enterpriseDao.selectEnterpriseStaffLists(serverOrder);
		if(selectEnterpriseStaffList==null||selectEnterpriseStaffList.size()==0){
			 return new ReturnData(12, "没有这个企业");
		}
		String selectStaff = userDao.selectStaff(selectUserInfoId);
		if(!StringTools.isEmpty(selectStaff)&&selectStaff.equals("1")){
			 return new ReturnData(12, "该用户已经加入了企业");	
		}
		EnterpriseInfo enterpriseInfo=new EnterpriseInfo();
		enterpriseInfo.setEnterprise_id(selectEnterpriseStaffList.get(0).get("id").toString());
		enterpriseInfo.setUser_id(selectUserInfoId);
		enterpriseInfo.setAudit("3");
		 int flag = enterpriseDao.addEnterpriseInfo(enterpriseInfo);
		 if(flag==1){
		 //添加自己的消息
         Map<String, Object> hm = new HashMap<>();
         hm.put("title", selectEnterpriseStaffList.get(0).get("company_name").toString()+"邀您入职");
         hm.put("type", "1");
         hm.put("recevicer_id", selectUserInfoId);
         hm.put("content", selectEnterpriseStaffList.get(0).get("company_name").toString()+"邀您入职");
         hm.put("enterprise_id", enterprise_user);
         int insertMessage = messageDao.insertMessage(hm);
         if (insertMessage == 1) {
			 return new ReturnData(200, "操作成功"); 
			 }
		 }
		  return new ReturnData(100, "操作失败");
	}
	 /**
	    * 员工同意加入企业
	    */
	@Override
	public ReturnData addUserEnterprise(String user_id, String enterprise_id,String msgId,String audit) {
		 if (StringTools.isEmpty(user_id) ||StringTools.isEmpty(enterprise_id)) {
	            return new ReturnData(12, "参数有误");
	        }	
		ServerOrder serverOrder = new ServerOrder();
			 serverOrder.setUser_id(enterprise_id);
			   List<Map<String, Object>> selectEnterpriseStaffList = enterpriseDao.selectEnterpriseStaffLists(serverOrder);
			if(selectEnterpriseStaffList==null||selectEnterpriseStaffList.size()==0){
				 return new ReturnData(12, "没有这个企业");
			}
			String selectUsertEnter = userDao.selectUsertEnter(user_id);
			if(!StringTools.isEmpty(selectUsertEnter)&&selectUsertEnter.equals("1")){
				 return new ReturnData(12, "您已经加入企业了");
			}	
			EnterpriseInfo enterpriseInfo = new EnterpriseInfo ();
			 enterpriseInfo.setEnterprise_id(selectEnterpriseStaffList.get(0).get("id").toString());
			 enterpriseInfo.setAudit(audit);
			 enterpriseInfo.setUser_id(user_id);
			 int flag = enterpriseDao.updateEnterpriseUser(enterpriseInfo);
			  if (flag == 1) {
					User user = new User();
					user.setUser_id(user_id);
					List<Map<String,Object>> selectStatus = userDao.selectStatus(user);
					if(selectStatus!=null&&selectStatus.size()>0&&selectStatus.get(0).get("status")!=null&&selectStatus.get(0).get("status").toString().equals("1")){
						user.setStatu("0");
						userDao.updateUserGrade(user);
					}
					User user2 = new User();
					user2.setParent_id(user_id);
					List<Map<String,Object>> selectStatus2 = userDao.selectStatus(user2);
					if(selectStatus2!=null&&selectStatus2.size()>0&&selectStatus2.get(0).get("status")!=null&&selectStatus2.get(0).get("status").toString().equals("1")){
						user2.setStatu("0");
						userDao.updateUserGrade(user2);
					}
				  int deleteMessage = messageDao.deleteMessage(msgId);
				  Map<String, Object> selectUserMobile = userDao.selectUserMobile(user_id);
				  if(audit.equals("1")){
					  if (deleteMessage == 1) {
						  //添加自己的消息
					         Map<String, Object> hm = new HashMap<>();
					         hm.put("title", "您成功加入"+selectEnterpriseStaffList.get(0).get("company_name").toString());
					         hm.put("type", "1");
					         hm.put("recevicer_id", user_id);
					         hm.put("content", "您成功加入"+selectEnterpriseStaffList.get(0).get("company_name").toString());
					         messageDao.insertMessage(hm);
					         //添加自己的消息
					         Map<String, Object> hd = new HashMap<>();
					         hd.put("title", selectUserMobile.get("username").toString()+"成功加入了您的企业");
					         hd.put("type", "1");
					         hd.put("recevicer_id", enterprise_id);
					         hd.put("content", selectUserMobile.get("username").toString()+"成功加入了您的企业");
					         messageDao.insertMessage(hd);
				  }
					  }else if(audit.equals("2")){
					  if (deleteMessage == 1) {
						  //添加自己的消息
					         Map<String, Object> hm = new HashMap<>();
					         hm.put("title", "您拒绝了"+selectEnterpriseStaffList.get(0).get("company_name").toString()+"的邀请");
					         hm.put("type", "1");
					         hm.put("recevicer_id", user_id);
					         hm.put("content", "您拒绝了"+selectEnterpriseStaffList.get(0).get("company_name").toString()+"的邀请");
					         messageDao.insertMessage(hm);
					         //添加自己的消息
					         Map<String, Object> hd = new HashMap<>();
					         hd.put("title", selectUserMobile.get("username").toString()+"拒绝了您的员工邀请");
					         hd.put("type", "1");
					         hd.put("recevicer_id", enterprise_id);
					         hd.put("content", selectUserMobile.get("username").toString()+"拒绝了您的员工邀请");
					         messageDao.insertMessage(hd);
				  }
				  }
		            return new ReturnData(200, audit.equals("1")?"加入成功":"拒绝成功");
		        }
		        return new ReturnData(100,audit.equals("1")?"加入失败":"拒绝失败");

	}
	 
	 /**
	  * -同意、拒绝
	  */
	@Override
	public ReturnData updateEnterpriseUser(EnterpriseInfo enterpriseInfo) {
		if (StringTools.isEmpty(enterpriseInfo.getUser_id())  || StringTools.isEmpty(enterpriseInfo.getEnterprise_id()) || StringTools.isEmpty(enterpriseInfo.getAudit()) ) {
            return new ReturnData(12, "参数有误");
        }
		int updateEnterpriseUser = enterpriseDao.updateEnterpriseUser(enterpriseInfo);
		if(enterpriseInfo.getAudit().equals("1")){
			User user = new User();
			user.setUser_id(enterpriseInfo.getUser_id());
			List<Map<String,Object>> selectStatus = userDao.selectStatus(user);
			if(selectStatus!=null&&selectStatus.size()>0&&selectStatus.get(0).get("status")!=null&&selectStatus.get(0).get("status").toString().equals("1")){
				user.setStatu("0");
				userDao.updateUserGrade(user);
			}
			User user2 = new User();
			user2.setParent_id(enterpriseInfo.getUser_id());
			List<Map<String,Object>> selectStatus2 = userDao.selectStatus(user2);
			if(selectStatus2!=null&&selectStatus2.size()>0&&selectStatus2.get(0).get("status")!=null&&selectStatus2.get(0).get("status").toString().equals("1")){
				user2.setStatu("0");
				userDao.updateUserGrade(user2);
			}
			  Map<String, Object> selectUserMobile = userDao.selectUserMobile(enterpriseInfo.getUser_id());
			  Map<String, Object> selectEnterId = enterpriseDao.selectEnterId(enterpriseInfo.getEnterprise_id());
			  //添加自己的消息
	        Map<String, Object> hm = new HashMap<>();
	        hm.put("title", selectUserMobile.get("username").toString()+"成功加入了您的企业");
	        hm.put("type", "1");
	        hm.put("recevicer_id", selectEnterId.get("user_id").toString());
	        hm.put("content", selectUserMobile.get("username").toString()+"成功加入了您的企业");
	        messageDao.insertMessage(hm);
	        //添加自己的消息
	        Map<String, Object> hd = new HashMap<>();
	        hd.put("title", "您成功加入"+selectEnterId.get("company_name").toString());
	        hd.put("type", "1");
	        hd.put("recevicer_id", enterpriseInfo.getUser_id());
	        hd.put("content", "您成功加入"+selectEnterId.get("company_name").toString());
	        messageDao.insertMessage(hd);
		}else if(enterpriseInfo.getAudit().equals("2")){
			  Map<String, Object> selectUserMobile = userDao.selectUserMobile(enterpriseInfo.getUser_id());
			  Map<String, Object> selectEnterId = enterpriseDao.selectEnterId(enterpriseInfo.getEnterprise_id());
			  //添加自己的消息
	        Map<String, Object> hm = new HashMap<>();
	        hm.put("title", "你拒绝了"+selectUserMobile.get("username").toString()+"的申请");
	        hm.put("type", "1");
	        hm.put("recevicer_id", selectEnterId.get("user_id").toString());
	        hm.put("content", "你拒绝了"+selectUserMobile.get("username").toString()+"的申请");
	        messageDao.insertMessage(hm);
	        //添加自己的消息
	        Map<String, Object> hd = new HashMap<>();
	        hd.put("title", selectEnterId.get("company_name").toString()+"拒绝了您的申请");
	        hd.put("type", "1");
	        hd.put("recevicer_id", enterpriseInfo.getUser_id());
	        hd.put("content", selectEnterId.get("company_name").toString()+"拒绝了您的申请");
		}
		
		  if (updateEnterpriseUser == 1) {
	            return new ReturnData(200, "成功");
	        }
	        return new ReturnData(100,"失败");
	}
	  /**
	    * 辞退
	    */
	@Override
	public ReturnData deleteEnterpriseUser(EnterpriseInfo enterpriseInfo) {
		if (StringTools.isEmpty(enterpriseInfo.getUser_id())  || StringTools.isEmpty(enterpriseInfo.getEnterprise_id()) ) {
            return new ReturnData(12, "参数有误");
        }
		
		
		
		OrderSend orderSend = new OrderSend();
		orderSend.setUser_id(enterpriseInfo.getUser_id());
		List<Map<String, Object>> selectOrderSendList = enterpriseDao.selectOrderSendList(orderSend);
		for (Map<String, Object> map : selectOrderSendList) {
			if(map.get("status")!=null&&map.get("status").toString().equals("待确认")||map.get("status").toString().equals("服务中")){
				   return new ReturnData(12, "请先完成未完成的订单！");		
			}
		}
		int updateEnterpriseUser = enterpriseDao.deleteEnterpriseUser(enterpriseInfo);
		  if (updateEnterpriseUser == 1) {
				User user = new User();
				user.setUser_id(enterpriseInfo.getUser_id());
				List<Map<String,Object>> selectStatus = userDao.selectStatus(user);
				if(selectStatus!=null&&selectStatus.size()>0&&selectStatus.get(0).get("status")!=null&&selectStatus.get(0).get("status").toString().equals("0")){
					user.setStatu("1");
					userDao.updateUserGrade(user);
				}
				User user2 = new User();
				user2.setParent_id(enterpriseInfo.getUser_id());
				List<Map<String,Object>> selectStatus2 = userDao.selectStatus(user2);
				if(selectStatus2!=null&&selectStatus2.size()>0&&selectStatus2.get(0).get("status")!=null&&selectStatus2.get(0).get("status").toString().equals("0")){
					user2.setStatu("1");
					userDao.updateUserGrade(user2);
				}
				
			  Map<String, Object> selectUserMobile = userDao.selectUserMobile(enterpriseInfo.getUser_id());
			  Map<String, Object> selectEnterId = enterpriseDao.selectEnterId(enterpriseInfo.getEnterprise_id());
			  //添加自己的消息
	        Map<String, Object> hm = new HashMap<>();
	        hm.put("title", "您已辞退"+selectUserMobile.get("username").toString());
	        hm.put("type", "1");
	        hm.put("recevicer_id", selectEnterId.get("user_id").toString());
	        hm.put("content", "您已辞退"+selectUserMobile.get("username").toString());
	        messageDao.insertMessage(hm);
	        //添加自己的消息
	        Map<String, Object> hd = new HashMap<>();
	        hd.put("title", "您已被"+selectEnterId.get("company_name").toString()+"辞退");
	        hd.put("type", "1");
	        hd.put("recevicer_id", enterpriseInfo.getUser_id());
	        hd.put("content", "您已被"+selectEnterId.get("company_name").toString()+"辞退");
	        messageDao.insertMessage(hd);
	            return new ReturnData(200, "成功");
	        }
	        return new ReturnData(100,"失败");
	}

	 /**
	  * 查询企业员工申请列表
	  */
	@Override
	public ReturnData selectEnterpriseUserList(EnterpriseInfo enterpriseInfo) {
		 if (StringTools.isEmpty(enterpriseInfo.getUser_id()) ) {
	            return new ReturnData(12, "参数有误");
	        }	
		 List<Map<String,Object>> selectEnterpriseUserList = enterpriseDao.selectEnterpriseUserList(enterpriseInfo);
		 if(selectEnterpriseUserList!=null&&selectEnterpriseUserList.size()>0){
			 return new ReturnData(selectEnterpriseUserList,200, ""); 
		 }
		  return new ReturnData(100, "暂无数据");
	}

	
	
}
